<template>
  <view class="container"> {{ JSON.stringify(certificates) }} </view>
</template>

<script>
import { baseURLWebApi } from "../../../utils/env";
import {
  uNavigateTo,
  uScanCode,
  uSetStorageSync,
  uRemoveStorageSync,
  uGetStorageSync,
} from "../../../utils/uniUtils";

export default {
  mounted() {
    let shortLink = uGetStorageSync("shortLinkTiktok");
    let header = {};
    const token = uGetStorageSync("token");

    if (token) {
      header["Authorization"] = `Bearer ${token}`;
    }
    uni.request({
      url: `${baseURLWebApi}/api/tiktok/CertificatePrepare`,
      header,
      data: {
        data: shortLink,
      },
      method: "POST",
      success(res) {
        let {
          data: { error_code, order_id, verify_token, certificates },
        } = res;

        if (error_code == 0) {
          this.certificates = certificates;
          this.form.verify_token = verify_token;
          this.form.certificates.push(certificates[0].encrypted_code);
        }
      },
    });

    uRemoveStorageSync("shortLinkTiktok");
  },

  data() {
    return {
      preData: null,
      certificates: [],
      form: {
        verify_token: "",
        encrypted_codes: [],
        poi_id: 6601142799414855694,
      },
    };
  },
  methods: {
    verify() {},
  },
};
</script>
